﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

namespace LuYao.Toolkit.Channels.DEncrypt
{
    public partial class AESViewModel : ViewModelBase
    {
        [ObservableProperty]
        private string _strContent1;
        [ObservableProperty]
        private string _strContent2;
        [ObservableProperty]
        private string _inputKey;
        [ObservableProperty]
        private string _inputIV;
        [RelayCommand]
        private void Encrypt()
        {
            if (string.IsNullOrWhiteSpace(this.StrContent1))
                return;
            if (string.IsNullOrWhiteSpace(this.InputKey))
                return;

            this.StrContent2 = Toolkit.DEncrypt.AES.EncryptByAES(this.StrContent1, this.InputKey, this.InputIV ?? "");
        }
        [RelayCommand]
        private void Decrypt()
        {
            if (string.IsNullOrWhiteSpace(this.StrContent1))
                return;
            if (string.IsNullOrWhiteSpace(this.InputKey))
                return;
            this.StrContent2 = Toolkit.DEncrypt.AES.DecryptByAES(this.StrContent1, this.InputKey, this.InputIV ?? "");

        }
        [RelayCommand]
        private void Clear()
        {
            this.StrContent1 = string.Empty;
            this.StrContent2 = string.Empty;
            this.InputKey = string.Empty;
            this.InputIV = string.Empty;
        }
        [RelayCommand]
        private void Copy()
        {
            if (string.IsNullOrWhiteSpace(this.StrContent2)) return;
            Services.ClipboardService.CopyText(this.StrContent2);
        }
    }
}
